package cn.com.ddapp.ddm.fragment.base.commidcontext;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.UserPepoleAdapter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.DetailsBean;
import cn.com.ddapp.ddm.fragment.base.BaseFragment;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.SPUtils;

/**
 * Created by Administrator on 2016/8/22 0022.商品详情页面，用户评价
 */
public class UsersContextFragment extends BaseFragment {
    @BindView(R.id.yongList)
    ListView yongList;
    @BindView(R.id.empty)
    EmptyLayout error_layout;
    @BindView(R.id.img_error_layout)
    ImageView img;
    @BindView(R.id.novalue)
    TextView novalue;
    private String userId;
    private DetailsBean.DetailBean.GoodsBean goods;
    private DetailsBean.DetailBean deBean;
    private List<DetailsBean.DetailBean.GoodKey> list;
    @Override
    protected String getFragmentTag() {
        return null;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
//        UserPepoleAdapter userPepoleAdapter=new UserPepoleAdapter(getContext());
//        yongList.setAdapter(userPepoleAdapter);
        userId = SPUtils.getStringData(getActivity(), SPUtils.USERID);
        toGetData(userId);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toGetData(userId);
            }
        });
    }

    private void toGetData(final String userId) {
        error_layout.setErrorType(EmptyLayout.NETWORK_LOADING);
        final OkUtilCallback okUtilCallback = new OkUtilCallback(error_layout) {
            @Override
            public void onMyResponse(String response, int id) {
                DetailsBean detailsBean = gson.fromJson(response, DetailsBean.class);
                if(!detailsBean.getResult().equals("OK")){
                    BaseApplication.showToast(detailsBean.getResult());
                    error_layout.setErrorType(EmptyLayout.NODATA);
                }else{
                    list=detailsBean.getDetail().getParamsList();
                    if(list.size()==0){
                        novalue.setVisibility(View.VISIBLE);
                    }else{
                        novalue.setVisibility(View.GONE);
                        UserPepoleAdapter userPepoleAdapter=new UserPepoleAdapter(getActivity(),list);
                        yongList.setAdapter(userPepoleAdapter);
                    }
                }
            }

        };
        Bundle bundle=getArguments();
        String goodsId =  AppConfig.GoodsId;
        if(bundle!=null)
        {
            goodsId = bundle.getString("goodsId");
        }
        String params="wid="+AppConfig.CITY_ID+"&id="+goodsId+"&userId="+userId;
        OKUtilAPI.post(OKUtilAPI.CommidUrl, params, okUtilCallback);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_yonghu;
    }


}
